package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.ProdFactoryEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.ProdFactoryEntityMapper;
import com.hzhr.iot.device.entity.ProdFactoryEntity;
import com.hzhr.iot.device.entity.ext.ProdFactoryEntityExt;
import com.hzhr.iot.device.queryModel.custom.ProdFactoryCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ProdFactoryDao {
    @Autowired
    ProdFactoryEntityMapper prodFactoryEntityMapper;
    @Autowired
    ProdFactoryEntityCustomMapper prodFactoryEntityCustomMapper;

    public int insert(ProdFactoryEntity record) {
        if (record == null) return 0;
        int changeCount = prodFactoryEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = prodFactoryEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ProdFactoryEntity record) {
        if (record == null) return 0;
        int changeCount = prodFactoryEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = prodFactoryEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ProdFactoryEntity selectEntity(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ProdFactoryEntityExt> extList = prodFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ProdFactoryEntity> selectEntityList(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ProdFactoryEntityExt> extList = prodFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ProdFactoryEntity> entityList = new ArrayList<>();
        for (ProdFactoryEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ProdFactoryEntityExt selectExt(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ProdFactoryEntityExt> extList = prodFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ProdFactoryEntityExt> selectExtList(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ProdFactoryEntityExt> extList = prodFactoryEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ProdFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = prodFactoryEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
